import axios from "axios";

const request = axios.create({
  baseURL: 'http://geek.itheima.net/v1_0/',
  timeout: 5000
})

request.interceptors.request.use((config) => {
  // 拦截请求，在请求头中添加token
  const token = window.localStorage.getItem('token')
  if (token) {
    config.headers.Authorization = `Bearer ${token}`
  }
  return config
}, (error) => {
  return Promise.reject(error)
})

request.interceptors.response.use((response) => {
  return response.data
}, (error) => {
  return Promise.reject(error)
})

export { request }